﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;


namespace EF_coreDemo
{
    public class DBContext : DbContext
    {
        //private readonly ILoggerFactory loggerFactory = LoggerFactory.Create(b => b.AddConsole());//查看ef 打印到控制台

        private string database = "love.db";
        public DbSet<Book> Books { get; set; }
        public DbSet<Person> Persons { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);

            optionsBuilder.UseSqlite($"data source = {database}");
            optionsBuilder.LogTo(Console.WriteLine);

            //var serverVersion = new MySqlServerVersion(new Version(8, 0, 36));

            //optionsBuilder.UseLoggerFactory(loggerFactory);//查看ef 打印到控制台

            //optionsBuilder.LogTo(Console.WriteLine);//查看ef全局信息 打印到控制台
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
        }
    }
}
